package cn.venny.doudian.controller;

import cn.venny.doudian.exception.ApiException;
import cn.venny.doudian.service.DoudianService;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Vick C
 * @date 2021/4/8
 */
@RestController
@RequestMapping("/doudian")
public class DouDianController {


    @Autowired
    DoudianService doudianService;

    @GetMapping("/accessToken")
    public Object getAccessToken(String code) {
        return JSON.toJSON(doudianService.getAccessToken(code));
    }

    @PostMapping("/orderList")
    public Object orderList(@RequestBody Map<String, Object> params) {
        return JSON.toJSON(doudianService.orderList(params));
    }

    @GetMapping("/logisticsCompanyList")
    public Object logisticsCompanyList(@RequestParam String accessToken) throws ApiException {
        return JSON.toJSON(doudianService.logisticsCompanyList(accessToken));
    }

    @GetMapping("/syncLogisticsCompanyToDb")
    public Object syncLogisticsCompanyToDb(String accessToken) throws ApiException {
        doudianService.syncLogisticsCompanyToDb(accessToken);
        return "success";
    }

    @PostMapping("/orderSearchList")
    public Object orderSearchList(@RequestBody Map<String, Object> params) throws ApiException {
        return JSON.toJSONString(doudianService.orderSearchList(params));
    }
}
